package com.example.mall.web.controller;

import com.example.mall.domain.SeckillActivities;
import com.example.mall.dto.SeckillActivitiesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.SeckillActivitiesQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ISeckillActivitiesService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/seckillActivities")
public class SeckillActivitiesController {

    @Autowired
    public ISeckillActivitiesService seckillActivitiesService;

    /**
     * 分页查询秒杀活动表信息
     * @param seckillActivitiesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询秒杀活动表信息",notes = "分页查询秒杀活动表信息",httpMethod = "GET")
    public JSONResult queryPage(SeckillActivitiesQuery seckillActivitiesQuery){
        PageDTO<SeckillActivitiesDto> seckillActivitiesDtoPageDTO = seckillActivitiesService.queryPage(seckillActivitiesQuery);
        return JSONResult.success("查询成功",seckillActivitiesDtoPageDTO);
    }

    /**
     * 根据id查询秒杀活动表信息
     * @param activityId
     * @return
     */
    @GetMapping("query/{activityId}")
    @ApiOperation(value = "根据id查询秒杀活动表信息",notes = "根据id查询秒杀活动表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("activityId")Long activityId){
        //1.根据id查询用户信息
        if (activityId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SECKILL_ACTIVITYID_NOT_ID);
        }
        SeckillActivities seckillActivities = seckillActivitiesService.getById(activityId);
        return JSONResult.success("查询成功",seckillActivities);
    }

    /**
     * 根据id查询秒杀活动表信息
     * @param activityId
     * @return
     */
    @GetMapping("querySeckillActivitiesById/{activityId}")
    @ApiOperation(value = "根据id查询秒杀活动表信息",notes = "根据id查询秒杀活动表信息",httpMethod = "GET")
    public JSONResult querySeckillActivitiesById(@PathVariable("activityId")Long activityId){
        //1.根据id查询用户信息
        if (activityId == null){
            throw new GlobalCustomerException(ErrorEnumCode.SECKILL_ACTIVITYID_NOT_ID);
        }
        SeckillActivities seckillActivities = seckillActivitiesService.querySeckillActivitiesById(activityId);
        return JSONResult.success("查询成功",seckillActivities);
    }

    /**
     * 查询全部秒杀活动表信息
     * @param
     * @return
     */
    @GetMapping("querySeckillActivitiesList")
    @ApiOperation(value = "查询全部秒杀活动表信息",notes = "查询全部秒杀活动表信息",httpMethod = "GET")
    public JSONResult querySeckillActivitiesList(){
        List<SeckillActivities> seckillActivities = seckillActivitiesService.querySeckillActivitiesList();
        return JSONResult.success("查询成功",seckillActivities);
    }

    /**
     * 新增秒杀活动表
     * @param seckillActivitiesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增秒杀活动表",notes = "新增秒杀活动表",httpMethod = "POST")
    public JSONResult insert(@RequestBody SeckillActivitiesDto seckillActivitiesDto){
        seckillActivitiesService.insert(seckillActivitiesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改秒杀活动表信息
     * @param seckillActivitiesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改秒杀活动表信息",notes = "修改秒杀活动表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody SeckillActivitiesDto seckillActivitiesDto){
        seckillActivitiesService.update(seckillActivitiesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除秒杀活动表信息
     * @param activityId
     * @return
     */
    @PostMapping("delete/{activityId}")
    @ApiOperation(value = "删除秒杀活动表信息",notes = "删除秒杀活动表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activityId") Long activityId) {
        seckillActivitiesService.delete(activityId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除秒杀活动表信息
     * @param activityIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除秒杀活动表信息",notes = "批量删除秒杀活动表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> activityIds) {
        seckillActivitiesService.deleteBatch(activityIds);
        return JSONResult.success("批量删除成功");
    }
}
